import json
from flask import current_app
from ronglian_sms_sdk import SmsSDK

class SmsTool:
    def __init__(self):
        accid = current_app.config.get("ACCID")
        acctoken = current_app.config.get("ACCTOKEN")
        appid = current_app.config.get("APPID")
        self.sdk = SmsSDK(accId=accid,accToken=acctoken,appId=appid)
    def send(self,mobile,code):
        tid = current_app.config.get('TID')
        time = current_app.config.get("TIME")
        res = self.sdk.sendMessage(tid,mobile,(code,time))
        rs = json.loads(res)
        if rs['statusCode'] == '000000':
            return True
        else:
            return False